//
//  MapView.swift
//  ChinaLandmark
//
//  Created by liy on 2025/2/6.
//

import MapKit
import SwiftUI

struct MapView: UIViewRepresentable {
  let center: CLLocationCoordinate2D

  func makeUIView(context: Context) -> MKMapView {
    return MKMapView()
  }

  func updateUIView(_ uiView: MKMapView, context: Context) {
    // span相当于比例尺：数字越小 地图越大
    //	latitudeDelta:地图上显示的南北举例（以度为单位，）南北纬供100度
    //	longtitudeDelta:地图上显示的东西距离（以度为单位）东西经共360度
    let span = MKCoordinateSpan(latitudeDelta: 0.02, longitudeDelta: 0.02)

    uiView.setRegion(
      MKCoordinateRegion(center: center, span: span), animated: true
    )
  }
}

#Preview {
  MapView(center: CLLocationCoordinate2D(
    latitude: 39.9087243,
    longitude: 116.3952859))
}
